
package com.jf.cloud.live.controller.app;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.live.dto.LiveProdStoreDTO;
import com.jf.cloud.live.model.LiveProdStore;
import com.jf.cloud.live.service.LiveProdStoreService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 直播商品
 *
 * @author zz
 * @date 2022-08-17 17:09:06
 */
@RestController("appLiveProdStoreController")
@RequestMapping("/live_prod_store")
@Tag(name = "直播商品")
public class LiveProdStoreController {

    @Autowired
    private LiveProdStoreService liveProdStoreService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取直播商品列表" , description = "分页获取直播商品列表")
    public ServerResponseEntity<PageVO<LiveProdStore>> page(@Valid PageDTO pageDTO, @ParameterObject LiveProdStoreDTO liveProdStoreDTO) {
        PageVO<LiveProdStore> liveProdStorePage = liveProdStoreService.page(pageDTO, liveProdStoreDTO);
        return ServerResponseEntity.success(liveProdStorePage);
    }

    @GetMapping
    @Operation(summary = "获取直播商品" , description = "根据liveProdStoreId获取直播商品")
    public ServerResponseEntity<LiveProdStore> getByLiveProdStoreId(@ParameterObject @RequestParam Long liveProdStoreId) {
        return ServerResponseEntity.success(liveProdStoreService.getByLiveProdStoreId(liveProdStoreId));
    }

    @PostMapping
    @Operation(summary = "保存直播商品" , description = "保存直播商品")
    public ServerResponseEntity<Void> save(@Valid @RequestBody LiveProdStoreDTO liveProdStoreDTO) {
        LiveProdStore liveProdStore = mapperFacade.map(liveProdStoreDTO, LiveProdStore.class);
        liveProdStoreService.save(liveProdStore);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新直播商品" , description = "更新直播商品")
    public ServerResponseEntity<Void> update(@Valid @RequestBody LiveProdStoreDTO liveProdStoreDTO) {
        LiveProdStore liveProdStore = mapperFacade.map(liveProdStoreDTO, LiveProdStore.class);
        liveProdStoreService.update(liveProdStore);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除直播商品" , description = "根据直播商品id删除直播商品")
    public ServerResponseEntity<Void> delete(@RequestParam Long liveProdStoreId) {
        liveProdStoreService.deleteById(liveProdStoreId);
        return ServerResponseEntity.success();
    }
}
